Repository navigation
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| static const auto jArguments = | ||
| jni::findClassStatic("com/facebook/react/bridge/Arguments"); | ||
| static jmethodID jMakeNativeMap = env->GetStaticMethodID( | ||
| jArguments, | ||
| jArguments.get(), | ||
| "makeNativeMap", | ||
| "(Ljava/util/Map;)Lcom/facebook/react/bridge/WritableNativeMap;"); | ||
| auto constants = env->CallStaticObjectMethod(jArguments, jMakeNativeMap, arg); | ||
| auto jResult = jni::adopt_local(constants); | ||
| auto result = jni::static_ref_cast<NativeMap::jhybridobject>(jResult); | ||
| return jsi::valueFromDynamic(rt, result->cthis()->consume()); | ||
| return jni::adopt_local( | ||
| static_cast<NativeMap::jhybridobject>( | ||
| env->CallStaticObjectMethod(jArguments.get(), jMakeNativeMap, arg))); |
There was a problem hiding this comment.
Let's migrate this to fbjni, so we get the normal error handling.
There was a problem hiding this comment.
Done in abae08e. Arguments.makeNativeMap() is now called through an fbjni JavaClass, so a value it can't convert throws a JniException and becomes a JS error.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| returnValue = | ||
| jsi::valueFromDynamic(runtime, nativeMap->cthis()->consume()); |
There was a problem hiding this comment.
Any chance nativeMap would be null?
There was a problem hiding this comment.
I don't think so, Arguments.makeNativeMap has a non-null return type and always returns the WritableNativeMap it creates, even for a null input. If a value can't be converted it throws, and fbjni turns that into a JniException before nativeMap is assigned.
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D129043188. |
159fcf6 to
abae08e
Compare
Summary:
JavaTurboModuleconverts a module'sgetConstants()result withArguments.makeNativeMap(). That throwsIllegalArgumentExceptionfor values it can't convert, such as aDateor aUri. The result wasn't checked, so the null map was used with the Java exception still pending, and ART aborted the app withJNI DETECTED ERROR IN APPLICATION: obj == null.This change:
Arguments.makeNativeMap()through an fbjniJavaClass, so a value it can't convert throws through fbjni's usual error handling and becomes a JS error.ArgumentsandmakeNativeMaponce, instead of callingFindClassand leaving its local reference behind on everygetConstants()call.Changelog:
[ANDROID] [FIXED] - Throw a JS error instead of crashing when a TurboModule's constants contain a value that can't be converted
Test Plan:
Release RNTester (
./gradlew :packages:rn-tester:android:app:assembleRelease -PreactNativeArchitectures=arm64-v8a) with these temporary, uncommitted changes:SampleTurboModuleadds ajava.util.Dateconstant when asked to.getConstants().SampleTurboModulecan't initialize in a minified build, which is a separate issue.On a Galaxy A16 (Android 16):
maingetConstants()with aDateconstantJNI DETECTED ERROR IN APPLICATION: obj == null, fromGetObjectFieldinJavaTurboModule::invokeJavaMethodException in HostFunction: java.lang.IllegalArgumentException: Could not convert class java.util.Date, followed by the Java stack tracegetConstants()with valid constants{"const3":"something","const1":true,"const2":1080}Not run: an automated test.
JavaTurboModulehas no host-side tests, and Fantom doesn't load Java modules.🤖 Generated with Claude Code